package com.bdmc.smokesensor.services;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bdmc.smokesensor.dao.Smk_HeartBeatJPA;
import com.bdmc.smokesensor.entity.Smk_HeartBeat;
import com.bdmc.smokesensor.iservices.ISmk_HeartBeatService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

@Service
public class Smk_HeartBeatService extends BaseService<Smk_HeartBeatService> implements ISmk_HeartBeatService {

    @Autowired
    private Smk_HeartBeatJPA _heartJpa;

    @Override
    public List<Smk_HeartBeat> findAll() {
        return null;
    }

    @Override
    public Map<String, Object> findByPageable(int depid,String imei, int page, int size) {
        String sql = "select hb.id,hb.smkDevicesId,hb.alarmDetail,hb.alarmStat,hb.oid,"
        +" DATE_FORMAT(hb.alarmTime,'%Y-%m-%d %H:%i:%S') alarmDate,DATE_FORMAT(hb.joinDate,'%Y-%m-%d %H:%i:%S') joinDate,"
        +" dv.devName,dv.devId,dv.imei from smk_heartbeat hb"
                + " LEFT JOIN smk_devices dv on dv.id=hb.smkDevicesId "
                + "  left join sys_department dep on dep.id=dv.departmentId "
                + " where (dep.id=" + depid
                + " or dep.treeRoot like '%," + depid + ",%') ";
        if (imei!=null&&imei.length()>0){
            sql += " and dv.imei= " + imei;
        }
           
        sql += " order by hb.alarmTime desc";
        List<Map<String, Object>> data = getListMapBySql(sql, page, size);
        int total = GetCountBySql(sql);

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("total", total);
        map.put("data", data);
        return map;
    }

    @Override
    public Smk_HeartBeat findOne(Example<Smk_HeartBeat> example) {
        return null;
    }

    @Override
    public Smk_HeartBeat findOneById(int id) {
        return null;
    }

    @Override
    public Smk_HeartBeat save(Smk_HeartBeat entity) {
        return _heartJpa.save(entity);
    }

	@Override
	public void deleteById(int id) {
		
	}

}